package test4;

import java.util.Scanner;

public class exchange {
    public static void main(String[] args){
        //输入金额
        Scanner sc=new Scanner(System.in);
        int money;
        for(int i=0;;i++){
            System.out.println("请输入金额：");
            money=sc.nextInt();
            if(money>=0&&money<=9999999){
                break;
            }else{
                System.out.println("金额无效");
            }
        }
        int count=0;
        //获取每一位，并且转变为大写
        String result="";
        while(money>0){
            int ge=money%10;
            count++;
            result=exChange(ge)+result;
            money/=10;
        }

        //变成9位，补零
        for(int i=0;i<7-count;i++){
            result="零"+result;
        }

        //补单位
        String exchanges="";
        String[] danWei={"佰","拾","万","仟","佰","拾","元"};
        for(int i=0;i<7;i++){
            exchanges=exchanges+result.charAt(i)+danWei[i];
        }

        //打印结果
        System.out.println( exchanges);
    }

    //方法：将一个数字转变成大写
    public static String exChange(int n){
        String[] bignumber={"零","壹","贰","叁","肆","伍","陆","柒","捌","玖"};
        return bignumber[n];
    }

}

